package com.examine.serviceImpl;

import com.examine.bean.MyApproval;
import com.examine.bean.User;
import com.examine.dao.MyApprovalMapper;
import com.examine.dao.UserMapper;
import com.examine.service.AccessApplicationService;
import com.examine.service.MyApprovalService;
import com.examine.service.NewsService;
import com.examine.utils.DataConfig;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class MyApprovalServiceImpl implements MyApprovalService {
    private static SqlSession session = null;
    private static MyApprovalMapper myApprovalMapper = null;
    private MyApproval myApproval = null;
    private List<MyApproval> myApprovalList = null;
    private int count = 0;

    public static void dataConfig(){
        try{
            session = DataConfig.getSession();
            myApprovalMapper = session.getMapper(MyApprovalMapper.class);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public int deleteByPrimaryKey(String id) {
        dataConfig();

        try{
            count = myApprovalMapper.deleteByPrimaryKey(id);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }


    @Override
    public int insertSelective(MyApproval record) {
        dataConfig();

        try{
            count = myApprovalMapper.insertSelective(record);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }

    @Override
    public MyApproval selectByPrimaryKey(String id) {
        dataConfig();

        try{
            myApproval = myApprovalMapper.selectByPrimaryKey(id);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return myApproval;
    }

    @Override
    public int updateByPrimaryKeySelective(MyApproval record) {
        dataConfig();

        try{
            count = myApprovalMapper.updateByPrimaryKeySelective(record);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }

    @Override
    public List<MyApproval> shareQueryMyApproval(MyApproval record) {
        dataConfig();

        try{
            myApprovalList = myApprovalMapper.shareQueryMyApproval(record);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return myApprovalList;
    }

    @Override
    public int updateSelective(MyApproval record) {
        dataConfig();

        try{
            count = myApprovalMapper.updateSelective(record);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }

}
